package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.GateReaderDao;
import com.pojo.GateReader;
import com.util.ValidateHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 刷卡记录
 */
@Service("gateReaderService")
public class GateReaderService extends ServiceImpl<GateReaderDao, GateReader> {

    @Autowired
    private GateReaderDao gateReaderDao;

    /**
     * 分页获取闸机刷卡信息
     * @param gateId 闸机ID，必填
     * @param cardNo 卡号,可选
     * @param uname 用户姓名,可选
     * @param page
     * @param limit
     * @return
     */
    public IPage<GateReader> getByPager(String gateId, String cardNo, String uname, Integer page, Integer limit) {
        Page p = new Page(page, limit);
        QueryWrapper q = new QueryWrapper();
        q.eq("gateId",gateId);
        if (ValidateHelper.isNotEmptyString(cardNo)) {
            q.eq("cid", cardNo);
        }
        if (ValidateHelper.isNotEmptyString(uname)) {
            q.like("uname", uname);
        }
        IPage<GateReader> iPage = gateReaderDao.selectPage(p, q);
        return iPage;
    }

}
